package zack.project.domain.activity.service.quota.policy.impl;

import zack.project.domain.activity.adapter.repository.IActivityRepository;
import zack.project.domain.activity.model.aggregate.CreateQuotaOrderAggregate;
import zack.project.domain.activity.model.valobj.OrderStateVO;
import zack.project.domain.activity.service.quota.policy.ITradePolicy;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**无需支付的交易节点
 * @author A1793
 */
@Service("rebate_no_pay_trade")
public class RebateNoPayTradePolicy implements ITradePolicy {
    private final IActivityRepository activityRepository;

    public RebateNoPayTradePolicy(IActivityRepository activityRepository) {
        this.activityRepository = activityRepository;
    }

    @Override
    public void trade(CreateQuotaOrderAggregate createQuotaOrderAggregate) {
        //无需支付的充值订单的状态直接设置为completed
        createQuotaOrderAggregate.setOrderState(OrderStateVO.completed);
        createQuotaOrderAggregate.getActivityOrderEntity().setPayAmount(BigDecimal.ZERO);
        //保存充值单并给用户的账户充值抽奖次数
        activityRepository.doSaveNoPayOrder(createQuotaOrderAggregate);

    }
}
